home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kparts / browserrun.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-10-01  |  7.9 KB  |  195 lines

  1. /* This file is part of the KDE project
  2.  *
  3.  * Copyright (C) 2002 David Faure <faure@kde.org>
  4.  * This library is free software; you can redistribute it and/or
  5.  * modify it under the terms of the GNU Library General Public
  6.  * License version 2, as published by the Free Software Foundation.
  7.  *
  8.  * This library is distributed in the hope that it will be useful,
  9.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  11.  * Library General Public License for more details.
  12.  *
  13.  * You should have received a copy of the GNU Library General Public License
  14.  * along with this library; see the file COPYING.LIB.  If not, write to
  15.  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16.  * Boston, MA 02110-1301, USA.
  17.  */
  18.  
  19. #ifndef kparts_browserrun_h
  20. #define kparts_browserrun_h
  21.  
  22. #include <krun.h>
  23. #include <kservice.h>
  24. #include <kparts/browserextension.h>
  25.  
  26. namespace KParts {
  27.  
  28.     /**
  29.      * This class extends KRun to provide additional functionality for browsers:
  30.      * <ul>
  31.      * <li>"save or open" dialog boxes
  32.      * <li>"save" functionality
  33.      * <li>support for HTTP POST (including saving the result to a temp file if
  34.      *   opening a separate application)
  35.      * <li>warning before launching executables off the web
  36.      * <li>custom error handling (i.e. treating errors as HTML pages)
  37.      * <li>generation of SSL metadata depending on the previous URL shown by the part
  38.      * </ul>
  39.      *
  40.      * @author David Faure <faure@kde.org>
  41.      */
  42.     class KPARTS_EXPORT BrowserRun : public KRun
  43.     {
  44.         Q_OBJECT
  45.     public:
  46.         /**
  47.          * @param url the URL we're probing
  48.          * @param args URL args - includes data for a HTTP POST, etc.
  49.          * @param part the part going to open this URL - can be 0L if not created yet
  50.          * @param window the mainwindow - passed to KIO::Job::setWindow()
  51.          * @param removeReferrer if true, the "referrer" metadata from @p args isn't passed on
  52.          * @param trustedSource if false, a warning will be shown before launching an executable
  53.          * Always pass false for @p trustedSource, except for local directory views.
  54.          */
  55.         BrowserRun( const KURL& url, const KParts::URLArgs& args,
  56.                     KParts::ReadOnlyPart *part, QWidget *window,
  57.                     bool removeReferrer, bool trustedSource );
  58.  
  59.         // BIC: merge with above constructor
  60.         /**
  61.          * @param url the URL we're probing
  62.          * @param args URL args - includes data for a HTTP POST, etc.
  63.          * @param part the part going to open this URL - can be 0L if not created yet
  64.          * @param window the mainwindow - passed to KIO::Job::setWindow()
  65.          * @param removeReferrer if true, the "referrer" metadata from @p args isn't passed on
  66.          * @param trustedSource if false, a warning will be shown before launching an executable.
  67.          * Always pass false for @p  trustedSource, except for local directory views.
  68.          * @param hideErrorDialog if true, no dialog will be shown in case of errors.
  69.          * 
  70.          */
  71.         BrowserRun( const KURL& url, const KParts::URLArgs& args,
  72.                     KParts::ReadOnlyPart *part, QWidget *window,
  73.                     bool removeReferrer, bool trustedSource, bool hideErrorDialog );
  74.  
  75.         virtual ~BrowserRun();
  76.  
  77.         //KParts::URLArgs urlArgs() const { return m_args; }
  78.         //KParts::ReadOnlyPart* part() const { return m_part; }
  79.  
  80.     /**
  81.      * @return the URL we're probing
  82.      */
  83.         KURL url() const { return m_strURL; }
  84.  
  85.     /**
  86.      * @return true if no dialog will be shown in case of errors
  87.      */
  88.         bool hideErrorDialog() const;
  89.  
  90.         /**
  91.      * @return Suggested filename given by the server (e.g. HTTP content-disposition filename)
  92.      */
  93.         QString suggestedFilename() const { return m_suggestedFilename; }
  94.  
  95.         /**
  96.      * @return Suggested disposition by the server (e.g. HTTP content-disposition)
  97.          * @since 3.5.2
  98.      */
  99.         QString contentDisposition() const;
  100.  
  101.         bool serverSuggestsSave() const { return contentDisposition() == QString::fromLatin1("attachment"); }
  102.  
  103.         enum AskSaveResult { Save, Open, Cancel };
  104.         /**
  105.          * Ask the user whether to save or open a url in another application.
  106.          * @param url the URL in question
  107.          * @param offer the application that will be used to open the URL
  108.          * @param mimeType the mimetype of the URL
  109.          * @param suggestedFilename optional filename suggested by the server
  110.          * @return Save, Open or Cancel.
  111.          */
  112.         static AskSaveResult askSave( const KURL & url, KService::Ptr offer, const QString& mimeType, const QString & suggestedFilename = QString::null );
  113.  
  114.         enum AskEmbedOrSaveFlags { InlineDisposition = 0, AttachmentDisposition = 1 };
  115.         /**
  116.          * Similar to askSave() but for the case where the current application is
  117.          * able to embed the url itself (instead of passing it to another app).
  118.          * @param url the URL in question
  119.          * @param mimeType the mimetype of the URL
  120.          * @param suggestedFilename optional filename suggested by the server
  121.          * @param flags set to AttachmentDisposition if suggested by the server
  122.          * @return Save, Open or Cancel.
  123.          */
  124.         static AskSaveResult askEmbedOrSave( const KURL & url, const QString& mimeType, const QString & suggestedFilename = QString::null, int flags = 0 );
  125.  
  126.         // virtual so that KHTML can implement differently (HTML cache)
  127.         virtual void save( const KURL & url, const QString & suggestedFilename );
  128.  
  129.         // static so that it can be called from other classes
  130.         static void simpleSave( const KURL & url, const QString & suggestedFilename,
  131.                                 QWidget* window );
  132.  
  133.         /** BIC: Combine with the above function for KDE 4.0. */
  134.         static void simpleSave( const KURL & url, const QString & suggestedFilename );
  135.  
  136.         static bool allowExecution( const QString &serviceType, const KURL &url );
  137.  
  138.         /** BIC: Obsoleted by KRun::isExecutable( const QString &serviceType ); */
  139.         static bool isExecutable( const QString &serviceType );
  140.         static bool isTextExecutable( const QString &serviceType );
  141.  
  142.     protected:
  143.         /**
  144.          * Reimplemented from KRun
  145.          */
  146.         virtual void scanFile();
  147.         /**
  148.          * Reimplemented from KRun
  149.          */
  150.         virtual void init();
  151.         /**
  152.          * Called when an error happens.
  153.          * NOTE: @p job could be 0L, if you passed hideErrorDialog=true.
  154.          * The default implementation shows a message box, but only when job != 0 ....
  155.          * It is strongly recommended to reimplement this method if
  156.          * you passed hideErrorDialog=true.
  157.          */
  158.         virtual void handleError( KIO::Job * job );
  159.  
  160.         /**
  161.          * NotHandled means that foundMimeType should call KRun::foundMimeType,
  162.          * i.e. launch an external app.
  163.          */
  164.         enum NonEmbeddableResult { Handled, NotHandled, Delayed };
  165.  
  166.         /**
  167.          * Helper for foundMimeType: call this if the mimetype couldn't be embedded
  168.          */
  169.         NonEmbeddableResult handleNonEmbeddable( const QString& mimeType );
  170.  
  171.     protected slots:
  172.         void slotBrowserScanFinished(KIO::Job *job);
  173.         void slotBrowserMimetype(KIO::Job *job, const QString &type);
  174.         void slotCopyToTempFileResult(KIO::Job *job);
  175.         virtual void slotStatResult( KIO::Job *job );
  176.  
  177.     protected:
  178.         KParts::URLArgs m_args;
  179.         KParts::ReadOnlyPart *m_part; // QGuardedPtr?
  180.         QGuardedPtr<QWidget> m_window;
  181.         // Suggested filename given by the server (e.g. HTTP content-disposition)
  182.         // When set, we should really be saving instead of embedding
  183.         QString m_suggestedFilename;
  184.         QString m_sMimeType;
  185.         bool m_bRemoveReferrer;
  186.         bool m_bTrustedSource;
  187.     private:
  188.         void redirectToError( int error, const QString& errorText );
  189.         class BrowserRunPrivate;
  190.         BrowserRunPrivate* d;
  191.  
  192.     };
  193. }
  194. #endif
  195.